package com.ruoyi.result.certificateinfo.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.certificateinfo.domain.ResultCertificateinfo;
import com.ruoyi.result.certificateinfo.domain.dto.ResultCertificateinfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 档案资料上传Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultCertificateinfoMapper
{
    /**
     * 查询档案资料上传
     *
     * @param id 档案资料上传主键
     * @return 档案资料上传
     */
    public ResultCertificateinfo selectResultCertificateinfoById(Long id);

    /**
     * 查询档案资料上传列表
     *
     * @param resultCertificateinfo 档案资料上传
     * @return 档案资料上传集合
     */
    public List<ResultCertificateinfo> selectResultCertificateinfoList(ResultCertificateinfoDTO resultCertificateinfo);

    /**
     * 新增档案资料上传
     *
     * @param resultCertificateinfo 档案资料上传
     * @return 结果
     */
    public int insertResultCertificateinfo(ResultCertificateinfo resultCertificateinfo);

    /**
     * 修改档案资料上传
     *
     * @param resultCertificateinfo 档案资料上传
     * @return 结果
     */
    public int updateResultCertificateinfo(ResultCertificateinfo resultCertificateinfo);

    /**
     * 删除档案资料上传
     *
     * @param id 档案资料上传主键
     * @return 结果
     */
    public int deleteResultCertificateinfoById(Long id);

    /**
     * 批量删除档案资料上传
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultCertificateinfoByIds(Long[] ids);

    List<ResultCertificateinfo> selectResultCertificateinfoByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_certificateinfo WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();


    @Select("SELECT YEAR(obtain_time) as year, COUNT(*) as count FROM result_certificateinfo " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(obtain_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(obtain_time) as year, COUNT(*) as count FROM result_certificateinfo " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(obtain_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);
}
